package classexercise;

import java.util.Arrays;
import java.util.Random;

public class Arraytest {

	public static void main(String[] args) {
		Arraytest arr = new Arraytest();
		arr.add();
        arr.modify();
        arr.delete();
	}

	public void add() {
		int[] a = new int[3];
		a[0] = 36;
		a[1] = 56;
		a[2] = 58;
		a = Arrays.copyOf(a, 5);
		a[3] = 67;
		a[4] = 75;
		System.out.println(Arrays.toString(a));
	}

	public void modify() {
		int a[]={1,5,6};
		a[0]=2;
		System.out.println(Arrays.toString(a));
	}
	public static void delete(){
		int[] arr = new int[10];
		Random r = new Random();
		for(int i=0;i<arr.length;i++){
			arr[i]=r.nextInt(3);
		}
		System.out.println(Arrays.toString(arr));	
		
		int count=0;
		int delNum=r.nextInt(2);
		for(int i:arr){
			if(i==delNum)
				count++;
		}
		int[] newArr = Arrays.copyOf(arr, arr.length-count);
		for(int i=0,j=0;j<newArr.length;i++){
			if(arr[i]!=delNum){
				newArr[j]=arr[i];
				j++;
			}
		}
		System.out.println(Arrays.toString(newArr)+"  delete:"+delNum);	
	}
	
}
